package com.lanyuan.a.service.impl;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.lanyuan.a.atest.BaseFormMap;
import com.lanyuan.a.bean.WindowFood;
import com.lanyuan.a.dao.BaseDao;
import com.lanyuan.a.service.WindowFoodService;
import com.lanyuan.plugin.PageView;
@Service("windowFoodService")
public class WindowFoodServiceImpl implements WindowFoodService {
	@Autowired
	public BaseDao<WindowFood> baseDao;
	
	@Override
	public List<WindowFood> list() {
		return baseDao.find("from WindowFood");
	}

	@Override
	public List<WindowFood> queryByPage(BaseFormMap formMap) {
		Long count = null;
		PageView pageView = (PageView)formMap.get("paging");
		int first = pageView.getPageNow();
		int max = pageView.getPageSize();
		String countHql = "select count (1) from WindowFood u ";
		count = baseDao.count(countHql);
		pageView.setRowCount(count);
		return baseDao.find("from WindowFood u ", new Object[]{}, first , max);
	}

	@Override
	public List<WindowFood> list(String wid) {
		return baseDao.find("from WindowFood where w_id = ?",new Object[]{Integer.parseInt(wid)});
	}

	@Override
	public List<WindowFood> queryWidByPage(BaseFormMap formMap, String wid , String orderType , String orderDirection) {
		PageView pageView = (PageView)formMap.get("paging");
		int first = pageView.getPageNow();
		int max = pageView.getPageSize();
		
		String countHql = "select count (1) from WindowFood u where w_id = ?";
		Long count = baseDao.count(countHql, new Object[]{Integer.parseInt(wid)});
		pageView.setRowCount(count);
		return baseDao.find("from WindowFood u where u.w_id = ?  order by "+orderType+"  desc ", new Object[]{Integer.parseInt(wid)}, first , max);
	}
	
	@Override
	public List<WindowFood> queryFtypeByPage(BaseFormMap formMap, String ftype , String orderType , String orderDirection) {
		PageView pageView = (PageView)formMap.get("paging");
		int first = pageView.getPageNow();
		int max = pageView.getPageSize();
		
		String countHql = "select count (1) from WindowFood u where f_type = ?";
		Long count = baseDao.count(countHql, new Object[]{ftype});
		pageView.setRowCount(count);
		return baseDao.find("from WindowFood u where u.f_type = ?  order by "+orderType+"  desc ", new Object[]{ftype}, first , max);
	}

	@Override
	public WindowFood getByWFid(int wfid) {
		return baseDao.get("from WindowFood u where u.w_f_id = ?", new Object[]{wfid});
	}

	@Override
	public void addFood(WindowFood ws) {
		baseDao.save(ws);
	}

	@Override
	public void updat(WindowFood ws) {
		baseDao.update(ws);
	}

}
